import React from "react";
import { notification } from "antd";
import "./index.scss";
interface IErrorBoundaryState {
  hasError: boolean;
}
export default class ErrorBoundary extends React.Component<any, IErrorBoundaryState> {
  constructor(props: any) {
    super(props);
    this.state = { hasError: false };
  }
  static getDerivedStateFromError() {
    return { hasError: true };
  }
  componentDidCatch(error: any) {
    notification.error({
      message: "Echarts渲染出错了",
      description: error?.message
    })
  }

  render() {
    if (this.state.hasError) {
      return <div className="error-boundary-wrapper">
        <h1>Visbar-Ecahrts Component Render Error.</h1>
      </div>;
    }
    return this.props.children; 
  }
}